home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / disk-man / linux-fl.000 / linux-fl / linux-floppies / fformat next >
Encoding:
Text File  |  1996-04-07  |  11.2 KB  |  371 lines

  1. #!/bin/sh
  2.  
  3. # ----------------------------------------------
  4. # fformat -- Linux Floppy Formatting Utility
  5. # -----------------------------------------------
  6. # (c) Nick Monyatovsky - nmonya01@barney.poly.edu
  7. # --- PITFALLS ---
  8. # Extra spaces after \ at the end of the line caused me much trouble.
  9. # Another pitfall is to write "xxx""yyyyy". SPACE must be in between them!
  10. # Manipulating block-size is not possible at the moment.
  11. # So, this option exists there, but is really cosmetic.
  12. # ALL disks are formatted with BLOCK_SIZE = 1024.
  13.  
  14.  
  15. # set this to point to the README file that came with the package, eg:
  16. # HELP_FILE="/usr/local/scripts/README"
  17. HELP_FILE="README"
  18.  
  19. # This allows you to customize this program for future use.
  20. # -------------------------- 
  21. # DEFAULT SETTINGS 
  22. # --------------------------
  23. # --- Disk size ("1440" or "720") in Kbytes
  24. DISK_SIZE="1440"
  25. # --- Linux device file that corresponds to that drive
  26. #     May be either "/dev/fd0" or "/dev/fd1"; rarely anything else.
  27. DEVICE_FILE="/dev/fd0"
  28. # --- verbose mode of operation ("ON" or "OFF")
  29. VERBOSE="ON"    
  30. # --- check for bad clusters ("ON" or "OFF")
  31. CHECK="ON"
  32. # --- Block size. (Usual values are "512" or "1024")
  33. BLOCK_SIZE="1024"
  34. # --- Inode density. (Usual values are "1024", "2048" or "4096")
  35. INODE_DENSITY="4096"
  36.  
  37. # colors must be used as follows:
  38. #       echo -ne (No Newline at the end, allow Escape sequences translation)
  39. COLOR1="\033[0m\033[37;44m"   # normal white  on blue 
  40. COLOR2="\033[1;6m\033[36;44m" # bright cyan on blue 
  41. COLOR3="\033[1;6m\033[31;40m" # bright red on black 
  42. COLOR_RESET="\033[0m" 
  43.  
  44.  
  45. # ---- Enter the main loop which you exit only when QUIT is pressed -----
  46. while [ 0 ]; do
  47.  
  48.  ##########################################
  49.  # ---------  MAIN WINDOW ----------------#
  50.  ###########--------------#################
  51. dialog \
  52.     --title "Linux Floppy Formatting" \
  53.     --menu "\n\
  54. This program will format a floppy and will create \n\
  55. an ext2 filesystem on it so that it will look as any \n\
  56. other linux drive (same long filenames, links, etc.) \n\
  57.                                                      \n\
  58. Current configuration: DEVICE: $DEVICE_FILE SIZE: $DISK_SIZE KB  \n\
  59. BLOCK SIZE: $BLOCK_SIZE bytes, INODE DENSITY: 1 per $INODE_DENSITY bytes" \
  60. 22 70 9 \
  61.   "START"       "Start formatting $DEVICE_FILE $DISK_SIZE KB" \
  62.   "QUIT"       "Exit"                          \
  63.   "EXPLAIN"       "Read \"README\" file" \
  64.   "DISK SIZE"      "Set disk size                      $DISK_SIZE KB " \
  65.   "DEVICE FILE"   "Linux device file for this drive   $DEVICE_FILE  " \
  66.   "BLOCK SIZE"       "Set the block size                 $BLOCK_SIZE bytes " \
  67.   "INODE DENSITY" "Set the inode density              1/$INODE_DENSITY bytes" \
  68.   "CHECK"       "Check for bad clustes              $CHECK      " \
  69.   "VERBOSE"       "Verbose operation                  $VERBOSE    " \
  70.   2> /tmp/ffloppy.temp
  71.  
  72.   if [ $? = 1 -o $? = 255 ]; then
  73.      rm -f /tmp/ffloppy.temp
  74.      # reset just restores the terminal if it got messy
  75.      reset
  76.      exit
  77.   fi
  78.  
  79.   MAINSELECT="`cat /tmp/ffloppy.temp`"
  80.   rm /tmp/ffloppy.temp
  81.  
  82.  # Start checking what to do. Some modules may reset MAINSELECT to run the
  83.  # next item in line.
  84.  # ------------------------------------------------------------------------
  85.  # PARAMETER SETTING WINDOWS
  86.  # ------------------------------------------------------------------------
  87.  
  88.  if [ "$MAINSELECT" = "EXPLAIN" ]; then
  89.     #echo "--- EXPLAIN was pressed ---"
  90.     if [ -f $HELP_FILE ]; then
  91.        dialog \
  92.         --title "Using Floppies Help" \
  93.         --textbox "$HELP_FILE" \
  94.         24 80
  95.        continue
  96.     else
  97.     dialog \
  98.        --title "Using Floppies Help" \
  99.        --msgbox "I am sorry, I cannot find \
  100. the README file. I can find it only when you run me out of that dirrectory \
  101. or if you have set the pointer to it on top of fformat script." \
  102.        15 70
  103.     fi
  104.  fi
  105.  
  106. if [ "$MAINSELECT" = "DISK SIZE" ] ; then
  107.     # echo " --- DISK SIZE was Pressed --- "
  108.     # --------------------------------------------------------
  109.     # SELECT DISK SIZE DIALOG
  110.     # --------------------------------------------------------
  111.     # It prompts the user for a value. Then that value is store
  112.     # in file /tmp/Fdrive_size, from where other programs may
  113.     dialog  --title "SELECT DRIVE SIZE" \
  114.     --menu "\n What is your disk size? \n " 13 40 2 \
  115.     "1440" "KB" \
  116.     "720"  "KB" \
  117.         2> /tmp/Fdisk_size
  118.  
  119.     if [ $? = 1 -o $? = 255 ]; then
  120.        rm -f /tmp/Fdisk_size 
  121.        # exit
  122.     fi
  123.     
  124.     DISK_SIZE=`cat /tmp/Fdisk_size`
  125.     rm -f /tmp/Fdisk_size
  126.     # echo DISK_SIZE is set to $DISK_SIZE
  127.         # echo "continuing"
  128.         # exit
  129.  fi
  130.  
  131.  if [ "$MAINSELECT" = "DEVICE FILE" ]; then
  132.     # echo "--- DEVICE FILE was pressed ---" 
  133.     # -----------------------------------
  134.     # SELECT DEVICE FILE DIALOG
  135.     # -----------------------------------
  136.     dialog     --title "SELECT FLOPPY DEVICE FILE" \
  137.             --menu "\n Select device file that \ncorresponds to your drive." \
  138.         12 50 2 \
  139.     "/dev/fd0"     "Generic floppy in drive A:" \
  140.     "/dev/fd1"     "Generic floppy in drive B:" \
  141.     2> /tmp/Fdevice_file
  142.     # "/dev/fd0H1440" "1.44M drive a:" \
  143.     # "/dev/fd1H1440" "1.44M drive b:" \
  144.     # "/dev/fd0h1200" "1.2M drive a:" \
  145.     # "/dev/fd1h1200" "1.2M drive b:" \
  146.  
  147.     if [ $? = 1 -o $? = 255 ]; then
  148.          rm -f /tmp/Fdevice_file 
  149.          # exit    
  150.     fi
  151.     
  152.     DEVICE_FILE="`cat /tmp/Fdevice_file`"
  153.     rm -f /tmp/Fdevice_file
  154.     # echo "DEVICE_FILE is set to $DEVICE_FILE"
  155.         # exit
  156. fi
  157.  
  158.  if [ "$MAINSELECT" = "BLOCK SIZE" ]; then
  159.     # echo "--- BLOCK SIZE was pressed ---"
  160.     # ------------------------------------------
  161.     # SELECT BLOCK SIZE DIALOG
  162.     # -------------------------------------------
  163.     dialog \
  164.     --title "SELECT BLOCK SIZE" \
  165.     --menu "\n\
  166. Smaller block size means less wasted space   \n\
  167.                          (and longer file reads). \n\
  168. Larger  block size means more wasted space   \n\
  169.                              (and faster file reads). \n\
  170. Unix standard is to use 1024 bytes which is \n\
  171. a good compromise between space and performance." \
  172.     18 65 3 \
  173.     "512"  "Better disk space utilization" \
  174.     "1024" "Standard for Unix systems" \
  175.     "2048" "Faster file access" \
  176.     2> /tmp/Fblock_size
  177.     
  178.     BLOCK_SIZE="`cat /tmp/Fblock_size`"
  179.     rm -f /tmp/Fblock_size
  180.  
  181.     if [ ! "$BLOCK_SIZE" = "2048" -a ! "$BLOCK_SIZE" = "1024" ]; then
  182.            BLOCK_SIZE=512
  183.     fi
  184.    
  185.     #echo "BLOCK_SIZE:  $BLOCK_SIZE bytes."
  186.     # exit
  187.  fi
  188.  
  189.  if [ "$MAINSELECT" = "INODE DENSITY" ]; then
  190.         #echo "--- INODE DENSITY was pressed ---"
  191.     # -----------------------------------------
  192.     # SELECT INODE DENSITY DIALOG
  193.         # -----------------------------------------  
  194.     dialog \
  195.     --title "SELECT INODE DENSITY" \
  196.     --menu "\
  197. Ext2 file system defaults to one inode per 4096 bytes \
  198. of drive space. EACH FILE requires ONE INODE. Therefore, \
  199. if you're going to have many small files on your drive, \
  200. you need more inodes (--> choose smaller value -- '2048' or '1024'). \
  201. However, more inodes also means slower file access. \
  202. If your files are not going to be small, then just hit return \
  203. to accept the default of 4096 bytes." \
  204.     18 65 3 \
  205.     "4096"     "1 inode per 4096 bytes. (default)" \
  206.     "2048"     "1 inode per 2048 bytes." \
  207.     "1024"     "1 inode per 1024 bytes." \
  208.     2> /tmp/Finode_density
  209.     
  210.     INODE_DENSITY="`cat /tmp/Finode_density`"
  211.     rm -f /tmp/Finode_density
  212.  
  213.     if [ ! "$INODE_DENSITY" = "2048" -a ! "$INODE_DENSITY" = "1024" ]; then
  214.            INODE_DENSITY=4096
  215.     fi
  216.    
  217.     #echo "Inode density: 1 inode per $INODE_DENSITY bytes."
  218.     # exit
  219.  fi
  220.  
  221.  if [ "$MAINSELECT" = "CHECK" ]; then
  222.     # echo "--- CHECK was pressed ---"
  223.     # --------------------------------------------------------
  224.     # CHECK FOR BAD CLUSTERS DIALOG
  225.     # --------------------------------------------------------
  226.     dialog --title "CHECK FOR BAD CLUSTERS" \
  227.     --menu "\n Set checking for bad clusters \n " 13 40 2 \
  228.     "ON"     "" \
  229.     "OFF"     "" \
  230.     2> /tmp/Fcheck_clusters
  231.  
  232.     if [ $? = 1 -o $? = 255 ]; then
  233.        rm -f /tmp/Fcheck_clusters 
  234.     #  exit
  235.     fi
  236.     
  237.     CHECK=`cat /tmp/Fcheck_clusters`
  238.     rm -f /tmp/Fcheck_clusters
  239.     # echo CHECK is set to $CHECK
  240.         # echo "continuing"
  241.      # exit
  242.  fi
  243.  
  244.  if [ "$MAINSELECT" = "VERBOSE" ]; then
  245.     # echo "--- VERBOSE was pressed ---"
  246.     # --------------------------------------------------------
  247.     # VERBOSE MODE DIALOG
  248.     # --------------------------------------------------------
  249.     dialog --title "VERBOSE MODE" \
  250.     --menu "\n Verbose mode \n " 13 40 2 \
  251.     "ON"     "" \
  252.     "OFF"     "" \
  253.     2> /tmp/Fverbose_mode
  254.  
  255.     if [ $? = 1 -o $? = 255 ]; then
  256.        rm -f /tmp/Fverbose_mode 
  257.     # exit
  258.     fi
  259.     
  260.     VERBOSE=`cat /tmp/Fverbose_mode`
  261.     rm -f /tmp/Fverbose_mode
  262.     # echo VERBOSE is set to $VERBOSE
  263.         # echo "continuing"
  264.      # exit
  265.  fi
  266.  
  267.  #------------------------------------
  268.  # ACTION PART OF THE PROGRAM
  269.  #------------------------------------
  270.  if [ "$MAINSELECT" = "START" ]; then
  271.     # echo "--- START was pressed ---"
  272.     # echo "Entering the main Part of the program"
  273.     # echo "Starting formatting"
  274.     if [ "$VERBOSE" = "ON" ]; then
  275.     VERBOSE_STRING=" -v "      
  276.     fi
  277.     if [ "$CHECK" = "ON" ]; then
  278.     CHECK_STRING=" -c "      
  279.     fi
  280.  
  281.     dialog \
  282.     --title "FORMATTING" \
  283.     --infobox "\
  284.                                     \n\
  285.               Device:  $DEVICE_FILE \n\
  286.                 Size:  $DISK_SIZE KB \n\
  287.      Filesystem type:  ext2          \n\
  288.           Block size:  $BLOCK_SIZE bytes\n\
  289.        Inode density:  1/$INODE_DENSITY bytes\n\
  290. Bad cluster checking:  $CHECK "       \
  291.     10 45
  292.  
  293.     echo -e $COLOR1        # set background to blue
  294.     # ======== /dev/fd0 disks ========================
  295.     if [ "$DEVICE_FILE" = "/dev/fd0" ]; then
  296.         umount /dev/fd0 1> /dev/null 2> /dev/null
  297.         if [ "$DISK_SIZE" = "1440" ]; then
  298.         fdformat /dev/fd0H1440
  299.         echo -ne $COLOR2 
  300.         echo "=========== Creating ext2 filesystem =============" 
  301.         echo -ne $COLOR1
  302.         mke2fs $CHECK_STRING -i $INODE_DENSITY $VERBOSE_STRING /dev/fd0 1440
  303.         echo -ne $COLOR2 
  304.         echo "===================  DONE  ======================="
  305.         echo -ne $COLOR1 
  306.         fi
  307.         if [ "$DISK_SIZE" = "720" ]; then
  308.         fdformat /dev/fd0D720
  309.         echo -ne $COLOR2 
  310.         echo "=========== Creating ext2 filesystem ============="
  311.         echo -ne $COLOR1 
  312.         mke2fs $CHECK_STRING -i $INODE_DENSITY $VERBOSE_STRING /dev/fd0 720
  313.         echo -ne $COLOR2 
  314.         echo "===================  DONE  ======================="
  315.         echo -ne $COLOR1 
  316.         fi
  317.     fi
  318.     # ======== /dev/fd1 disks ========================
  319.     if [ "$DEVICE_FILE" = "/dev/fd1" ]; then
  320.             umount /dev/fd1 1> /dev/null 2> /dev/null
  321.         if [ "$DISK_SIZE" = "1440" ]; then
  322.         fdformat /dev/fd1H1440
  323.         echo -ne $COLOR2 
  324.         echo "=========== Creating ext2 filesystem ============="
  325.         echo -ne $COLOR1 
  326.         mke2fs $CHECK_STRING -i $INODE_DENSITY $VERBOSE_STRING /dev/fd1 1440
  327.         echo -ne $COLOR2 
  328.         echo "===================  DONE  ======================="
  329.         echo -ne $COLOR1 
  330.         fi
  331.         if [ "$DISK_SIZE" = "720" ]; then
  332.         fdformat /dev/fd1D720
  333.         echo -ne $COLOR2 
  334.         echo "=========== Creating ext2 filesystem ============="
  335.         echo -ne $COLOR1 
  336.         mke2fs $CHECK_STRING -i $INODE_DENSITY $VERBOSE_STRING /dev/fd1 720
  337.         echo -ne $COLOR2 
  338.         echo "===================  DONE  ======================="
  339.         echo -ne $COLOR1 
  340.         fi
  341.     fi
  342.         sleep 1
  343.     echo -ne $COLOR_RESET    # Reset colors to normal (black)
  344.     # -------------------
  345.     # FORMAT ANOTHER? BOX
  346.     # -------------------
  347.     dialog     --title "FORMATTING"\
  348.         --yesno "\n  Format another?   \n" 8 25
  349.  
  350.     if [ $? = 1 -o $? = 255 ]; then
  351.         reset
  352.          exit
  353.     fi
  354. fi
  355.  
  356.  
  357. if [ "$MAINSELECT" = "QUIT" ]; then
  358.    reset    # restore the monitor properties
  359.    exit
  360. fi
  361.  
  362.  
  363. done 
  364. # ------- end of main loop -----------------
  365.  
  366.    
  367.  
  368.  
  369.  
  370.